<template>
  <view class="content">
    <image class="logo" src="/static/logo.png"></image>
    <view class="text-area">
      <text class="title">{{ title }}</text>
    </view>
    <button size="mini" type="primary" @click="toPage(pages.login)">蒙速办授权认证测试</button>
    <button size="mini" type="primary" style="margin-top: 10px;" @click="toPage(pages.eSign)">电子签名测试</button>
    <button size="mini" style="margin-top: 10px;" @click="toPage(pages.pdf)">pdf测试</button>
    <button size="mini" style="margin-top: 10px;" @click="toPage(pages.other)">其他测试</button>
    <scroll-view scroll-y>
      <view v-for="(item,index) in history" :key="index" style="margin-left: 30px;">
        <view v-if="item.hidden" style="color:#666;margin-top: 10px;">
          隐藏
          <text style="margin-left: 10px;font-size: small;">{{ item.time }}</text>
        </view>
        <view v-else style="color: aqua;">
          显示
          <text style="margin-left: 10px;font-size: small;">{{ item.time }}</text>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>

export default {
  data() {
    return {
      title: 'Hello',
      history: [],
      pages: {
        login: "/pages/login/login",
        eSign: "/pages/login/sign",
        pdf: "/pages/login/pdf",
        other: "/pages/login/other",
      }
    }
  },
  onLoad() {
    document.addEventListener('visibilitychange', () => {
      console.log('监听页面返回----', document.hidden);
      this.history.push({
        hidden: document.hidden,
        time: this.getCurrentTime()
      })
      // if (!document.hidden) { // 页面隐藏
      //     console.log("")
      // }
    }, false)
    // alert("this.$store.state.authLogin"+this.$store.state.authLogin)
    // if (!this.$store.state.authLogin) this.login()
  },
  methods: {
    toPage(url) {
      uni.navigateTo({url})
    },
    getCurrentTime() {
      var date = new Date(); //当前时间
      var year = date.getFullYear() //返回指定日期的年份
      var month = this.repair(date.getMonth() + 1); //月
      var day = this.repair(date.getDate()); //日
      var hour = this.repair(date.getHours()); //时
      var minute = this.repair(date.getMinutes()); //分
      var second = this.repair(date.getSeconds()); //秒
      //当前时间
      var curTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
      return curTime;
    },
    repair(i) {
      if (i >= 0 && i <= 9) return "0" + i;
      else return i;
    },
    showToast(title) {
      uni.showToast({title})
    },
  }
}
</script>

<style>
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.logo {
  height: 100px;
  width: 100px;
  margin-top: 100px;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 25px;
}

.text-area {
  display: flex;
  justify-content: center;
}

.title {
  font-size: 18px;
  color: #8f8f94;
}
</style>
